package com.goldsprite.gesturerecognizer.core.utils;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;

public class FontManager {
	private BitmapFont titleFont;
	private BitmapFont normalFont;
	private BitmapFont smallFont;

	public FontManager() {
		loadFonts();
	}

	private void loadFonts() {
		String fontName = "ipix_12px_6000.ttf";
		String fontName2 = "pixelFont-7-8x14-sproutLands.ttf";
		String fontName3 = "NotoSansMonoCJKsc-Regular.otf";
		try {
			FreeTypeFontGenerator generator = new FreeTypeFontGenerator(
				Gdx.files.internal("assets/fonts/"+fontName2)
			);

			FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();

			// 标题字体
			parameter.size = 24;
			parameter.borderWidth = 1;
			titleFont = generator.generateFont(parameter);

			// 正文字体
			parameter.size = 18;
			parameter.borderWidth = 0.5f;
			normalFont = generator.generateFont(parameter);

			// 小字体
			parameter.size = 14;
			parameter.borderWidth = 0;
			smallFont = generator.generateFont(parameter);

			generator.dispose();

			Gdx.app.log("FontManager", "Fonts loaded successfully");
		} catch (Exception e) {
			Gdx.app.error("FontManager", "Failed to load custom font, using default", e);
			// 备用默认字体
			titleFont = new BitmapFont();
			normalFont = new BitmapFont();
			smallFont = new BitmapFont();
		}
	}

	public BitmapFont getTitleFont() {
		return titleFont;
	}

	public BitmapFont getNormalFont() {
		return normalFont;
	}

	public BitmapFont getSmallFont() {
		return smallFont;
	}

	public void dispose() {
		titleFont.dispose();
		normalFont.dispose();
		smallFont.dispose();
	}
}
